home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet internetowy / Przegladarki internetowe / Mozilla Seamonkey 1.0.5 pl / seamonkey-1.0.5.pl-PL.win32.installer.exe / BROWSER.XPI / bin / chrome / toolkit.jar / content / global / printPreviewProgress.js < prev    next >
Encoding:
JavaScript  |  2004-08-26  |  5.7 KB  |  185 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Mozilla Communicator client code, released
  16.  * March 31, 1998.
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * Netscape Communications Corporation.
  20.  * Portions created by the Initial Developer are Copyright (C) 1998
  21.  * the Initial Developer. All Rights Reserved.
  22.  *
  23.  * Contributor(s):
  24.  *   Rod Spears <rods@netscape.com>
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  28.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. // dialog is just an array we'll use to store various properties from the dialog document...
  41. var dialog;
  42.  
  43. // the printProgress is a nsIPrintProgress object
  44. var printProgress = null; 
  45.  
  46. // random global variables...
  47. var targetFile;
  48.  
  49. var progressParams = null;
  50.  
  51. // all progress notifications are done through the nsIWebProgressListener implementation...
  52. var progressListener = {
  53.     onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
  54.     {
  55.       
  56.       if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
  57.       {
  58.         window.close();
  59.       }
  60.     },
  61.     
  62.     onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
  63.     {
  64.       if (progressParams)
  65.       {
  66.         dialog.title.crop = progressParams.docTitle ? "end" : "center";
  67.         dialog.title.value = progressParams.docTitle || progressParams.docURL;
  68.       }
  69.     },
  70.  
  71.       onLocationChange: function(aWebProgress, aRequest, aLocation)
  72.     {
  73.       // we can ignore this notification
  74.     },
  75.  
  76.     onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
  77.     {
  78.       if (aMessage != "")
  79.         dialog.title.setAttribute("value", aMessage);
  80.     },
  81.  
  82.     onSecurityChange: function(aWebProgress, aRequest, state)
  83.     {
  84.       // we can ignore this notification
  85.     },
  86.  
  87.     QueryInterface : function(iid)
  88.     {
  89.      if (iid.equals(Components.interfaces.nsIWebProgressListener) || 
  90.          iid.equals(Components.interfaces.nsISupportsWeakReference) ||
  91.          iid.equals(Components.interfaces.nsISupports))
  92.       return this;
  93.      
  94.      throw Components.results.NS_NOINTERFACE;
  95.     }
  96. };
  97.  
  98. function onLoad() {
  99.     // Set global variables.
  100.     printProgress = window.arguments[0];
  101.  
  102.     if ( !printProgress ) {
  103.         dump( "Invalid argument to printPreviewProgress.xul\n" );
  104.         window.close()
  105.         return;
  106.     }
  107.  
  108.     dialog          = new Object;
  109.     dialog.strings  = new Array;
  110.     dialog.title      = document.getElementById("dialog.title");
  111.     dialog.titleLabel = document.getElementById("dialog.titleLabel");
  112.  
  113.     if (window.arguments[1]) {
  114.       progressParams = window.arguments[1].QueryInterface(Components.interfaces.nsIPrintProgressParams)
  115.       if (progressParams) {
  116.         dialog.title.crop = progressParams.docTitle ? "end" : "center";
  117.         dialog.title.value = progressParams.docTitle || progressParams.docURL;
  118.       }
  119.     }
  120.  
  121.     // set our web progress listener on the helper app launcher
  122.     printProgress.registerListener(progressListener);
  123.     moveToAlertPosition();
  124.  
  125.     //We need to delay the set title else dom will overwrite it
  126.     window.setTimeout(doneIniting, 100);
  127. }
  128.  
  129. function onUnload() 
  130. {
  131.   if (printProgress)
  132.   {
  133.    try 
  134.    {
  135.      printProgress.unregisterListener(progressListener);
  136.      printProgress = null;
  137.    }
  138.     
  139.    catch( exception ) {}
  140.   }
  141. }
  142.  
  143. function getString( stringId ) {
  144.    // Check if we've fetched this string already.
  145.    if (!(stringId in dialog.strings)) {
  146.       // Try to get it.
  147.       var elem = document.getElementById( "dialog.strings."+stringId );
  148.       try {
  149.         if ( elem
  150.            &&
  151.            elem.childNodes
  152.            &&
  153.            elem.childNodes[0]
  154.            &&
  155.            elem.childNodes[0].nodeValue ) {
  156.          dialog.strings[ stringId ] = elem.childNodes[0].nodeValue;
  157.         } else {
  158.           // If unable to fetch string, use an empty string.
  159.           dialog.strings[ stringId ] = "";
  160.         }
  161.       } catch (e) { dialog.strings[ stringId ] = ""; }
  162.    }
  163.    return dialog.strings[ stringId ];
  164. }
  165.  
  166. // If the user presses cancel, tell the app launcher and close the dialog...
  167. function onCancel () 
  168. {
  169.   // Cancel app launcher.
  170.    try 
  171.    {
  172.      printProgress.processCanceledByUser = true;
  173.    }
  174.    catch( exception ) {return true;}
  175.     
  176.   // don't Close up dialog by returning false, the backend will close the dialog when everything will be aborted.
  177.   return false;
  178. }
  179.  
  180. function doneIniting() 
  181. {
  182.   // called by function timeout in onLoad
  183.   printProgress.doneIniting();
  184. }
  185.